package com.chinabank.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.chinabank.dao.PermissionDao;
import com.chinabank.model.Group;
import com.chinabank.model.Permission;


@Repository(value = "permissionDao")
public class PermissionDaoImpl extends BaseDaoImpl<Permission> implements
		PermissionDao {

	@Override
	public List<Permission> getPermissions() {
		String hql = "from Permission";
		Session session = this.getSessionFactory().getCurrentSession();
		List<Permission> permissions = session.createQuery(hql).list();
		return permissions;
	}

	@Override
	public List<Permission> getPermissions(Group gp) {
		String hql ="select permission from Group as g where g.id=?";
		Session session = this.getSessionFactory().getCurrentSession();
		List<Permission> permissions = session.createQuery(hql).setLong(0, gp.getId()).list();
		return permissions;
	}
}
